
window.onload= function () {

    var oScript=document.createElement("script");
    oScript.src="http://sclub.jd.com/productpage/p-10573378941-s-0-t-3-p-"+0+".html?callback=callback";
    document.body.appendChild(oScript);

    //获取按钮
    var form=$("botp"),
        oInput=form.getElementsByTagName("a");

        for(var i = 0;i<oInput.length;i++){
            //添加索引
            oInput[i].index=i;
            //点击按钮，改变路径
            oInput[i].onclick= function () {
                var oScript=document.createElement("script");
                oScript.src="http://sclub.jd.com/productpage/p-10573378941-s-0-t-3-p-"+this.index+".html?callback=callback";
                document.body.appendChild(oScript);
            }
        }

     var content=1;
      var cont=1;
     $("jian").onclick= function () {
     content++;

       $("inpt").value=content;
        cont=parseInt($("inpt").value)
       $("spa").innerHTML=content;

        cont=parseInt($("spa").innerHTML)
       $("emt").innerHTML=(content*($("eat").innerHTML));

     }

     $("jan").onclick= function () {
     content--;
     if(content<1){
     content=1;
     }
       $("inpt").value=content;
        cont=parseInt($("inpt").value);
        $("spa").innerHTML=content;
       cont=parseInt($("spa").innerHTML);
      $("emt").innerHTML=(content*($("eat").innerHTML));
   }
       cont=1;

        var sAtter = getCookie("attr1");
         console.log(sAtter);
       $("addShopCar").onclick=function () {
        var bBtn = true;
        var oAttr = getCookie('attr');

        if(oAttr === undefined){
            var shopCar =[];
        }else{
            var shopCar = JSON.parse(oAttr) ;
        }
        for(var i=0;i<shopCar.length;i++){
            if(shopCar[i].attrName == $("hami").innerHTML){
                var num = parseInt(shopCar[i].attrNum);
                num += cont;
                shopCar[i].attrNum = num;
                bBtn = false;
            }
        }
        if(bBtn){
            var attr = {
                attrName: $("hami").innerHTML,
                attrPrice: $("eat").innerHTML,
                attrSrc:  $("imgSrc").src,
                attrNum: 	cont,

            };
            shopCar.push(attr,sAtter);
        }
        setCookie('attr',JSON.stringify(shopCar),7,"/");
    }



};

function callback(data){

    for(var i=0;i<data.comments.length;i++){
        var
             oDv= $("dv"),
            oList=getClass(oDv,"bot-tp"),
            oDiv=oList[i].getElementsByTagName("div"),
            oP=oDiv[0].getElementsByTagName("p"),
            oSan=oDiv[0].getElementsByTagName("span"),
            oSpa=oDiv[1].getElementsByTagName("span"),
            oEm=oDiv[1].getElementsByTagName("em"),
            oRi=oDiv[1].getElementsByTagName("p");

        oP[0].innerHTML="收到货"+data.comments[i].days+"天后评论";
        oEm[0].innerHTML=data.comments[i].referenceTime;
        oSpa[0].innerHTML=data.comments[i].productColor+"&nbsp;"+data.comments[i].productSize;
        oRi[0].innerHTML=data.comments[i].content;
        oSan[0].innerHTML=data.comments[i].nickname;

    }

}

function $(id){
    return document.getElementById(id);
}
    function getClass(obj,sClassName){
        if(obj.getElementsByClassName){
            return obj.getElementsByClassName(sClassName);
        }else{
            var
                aAllTag = obj.getElementsByTagName("*"),
                aClass = [];
            for (var i=0;i< aAllTag;i++){
                if(aAllTag[i].className===sClassName){
                    aClass.push(aAllTag[i]);
                }
            }
            return aClass;
        }
    }